//
//  BBDragStrip.m
//  xNose
//
//  Created by ben smith on 15/09/08.
//  Copyright 2008 __MyCompanyName__. All rights reserved.
//

#import "BBDragStrip.h"
#import "BBLibraryView.h"


@implementation BBDragStrip

@synthesize delegate;
@synthesize backgroundGradient;

- (id)initWithFrame:(NSRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code here.
			[self setupBackgroundGradient];
    }
    return self;
}

// just draw a slightly lighter strip
- (void)drawRect:(NSRect)rect {
    // Drawing code here.
//	[[NSColor redColor] set];
	[[NSColor colorWithDeviceWhite:1.0 alpha:0.1] set];
	[self.backgroundGradient drawInRect:[self bounds] angle:90];
}


- (void)setupBackgroundGradient
{
	// create a basic gradient for the background of the view
	
	NSColor* gradientTop    = [NSColor colorWithCalibratedRed:0.0 green:0.0 blue:0.0 alpha:0.5];    
	NSColor* gradientMid = [NSColor colorWithCalibratedRed:1.0 green:1.0 blue:1.0 alpha:0.5];
	NSColor* gradientBottom    = [NSColor colorWithCalibratedRed:0.0 green:0.0 blue:0.0 alpha:0.5];    
	
	NSGradient* gradient;
	gradient = [[NSGradient alloc] initWithColorsAndLocations:gradientTop, 1.0f, gradientMid, 0.5f, gradientBottom, 0.01f, nil];
	
	self.backgroundGradient = gradient;
	[gradient release];
} 



-(void)otherMouseDown:(NSEvent*)theEvent
{
	[self mouseDown:theEvent];
}

-(void)otherMouseUp:(NSEvent*)theEvent
{
	[self mouseUp:theEvent];
}

-(void)otherMouseDragged:(NSEvent*)theEvent
{
	[self mouseDragged:theEvent];
}


// suck up extra mouse events
-(void)mouseDown:(NSEvent*)theEvent
{
	mouseDown = [theEvent locationInWindow];	
}

-(void)mouseUp:(NSEvent*)theEvent
{

}

// scroll the libview
-(void)mouseDragged:(NSEvent*)theEvent
{
	NSPoint newMouse = [theEvent locationInWindow];
	float adjust = newMouse.y - mouseDown.y;
	[delegate adjustVertical:adjust];
	mouseDown = newMouse;
}

@end
